package com.zjj.day0425.string;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date 2025/4/25
 */
import java.util.Arrays;
import java.util.Comparator;

public class StringArraySorting {
    public static void main(String[] args) {
        String[] arr = {"nba", "abc", "cba", "zz", "qq", "haha"};

        // 方式一：数组中元素自身具备比较性
        String[] arr1 = arr.clone();
        Arrays.sort(arr1);
        System.out.println("方式一排序结果：");
        for (String str : arr1) {
            System.out.print(str + " ");
        }
        System.out.println();

        // 方式二：容器具备比较性，传入 Comparator 比较器
        String[] arr2 = arr.clone();
        Arrays.sort(arr2, new Comparator<String>() {
            @Override
            public int compare(String s1, String s2) {
                return s1.compareTo(s2);
            }
        });
        System.out.println("方式二排序结果：");
        for (String str : arr2) {
            System.out.print(str + " ");
        }
    }
}